package com.baizhi.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class FirstAspect {

    @Pointcut("execution(* com.baizhi.service..*.*(..))")
    public void mx() {

    }

    //前置通知
    @Before("mx()")
    public void before() {
        System.out.println("before......");
    }

    //环绕通知
    @Around("mx()")
    public Object around(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("环绕通知之前......");
        Object obj = jp.proceed();
        System.out.println("环绕通知之后......");
        return obj;
    }

    //后置通知
    @AfterReturning(value="mx()",returning = "msg")
    public void afterReturing(int msg) {
        System.out.println("后置通知......");
        System.out.println("--------------------------------"+msg);
    }

    //异常通知
    @AfterThrowing(value = "mx()", throwing = "e")
    public void afterThrow(Throwable e) {
        System.out.println("异常通知......" + e.getMessage());
    }

    //最终通知
    @After("mx()")
    public void after() {
        System.out.println("最终通知......");
    }

}
